/*
 *  loader.c
 *  Amano Engine
 *
 *  Created by Aurelien Serandour on 07/03/11.
 *  Copyright 2011 __MyCompanyName__. All rights reserved.
 *
 */

#include <stdio.h>
#include <stdlib.h>

#include "../include/loader.h"
/*
#ifdef __cplusplus
extern "C"
{
#endif*/
	char* LoadShader(const char *filename)
	{
		FILE *fp = fopen(filename, "r");
		
		if (fp ==NULL)
		{
			printf( "failed to open shader %s\n", filename);
			return NULL;
		}
		
		fseek(fp, 0, SEEK_END); // look for the end of the file
		long size = ftell(fp);
		
		rewind(fp); // back to the beginning!
		//fseek(fp, 0, SEEK_SET);
		
		char* toRet = (char*)malloc(size+1);
		
		if (toRet == NULL)
		{
			fclose(fp);
			printf( "shader allocation went wrong: %s\n", filename);
			return NULL;
		}
		
		//time to copy
		int i;
		for ( i=0; i<size; i++)
		{
			toRet[i] == fgetc(fp);
		}
		
		toRet[size] = '\0';
		
		fclose(fp);
		
		return toRet;
	}
/*
#ifdef __cplusplus
}
#endif
*/